//
//  AssetDetailViewController.m
//  AppleMarket
//
//  Created by yangy on 01/11/2018.
//  Copyright © 2018 szgsy. All rights reserved.
//

#import "AssetDetailViewController.h"
// view
#import "AssetDetailMainView.h"
// viewModel
#import "AssetDetailViewModel.h"
// controller
#import "PushCoinViewController.h"
#import "PullCoinViewController.h"
#import "WalletViewController.h"
#import "CoinRecordViewController.h"
#import "SafePwdSetViewController.h"
#import "CoinListViewController.h"

@interface AssetDetailViewController ()
@property (nonatomic, strong) AssetDetailMainView *mainView;
@property (nonatomic, strong) AssetDetailViewModel *viewModel;
@end

@implementation AssetDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"币币账户";
    [self.view addSubview:self.mainView];
    [_mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [self bindViewModel];
}

- (void) bindViewModel
{
    [self.viewModel.pullClickSubject subscribeNext:^(id  _Nullable x) {
        // 提币
        if(![PlistCommon loginModel].IsSafePwd){
            UIAlertController *alterVC = [UIAlertController alertControllerWithTitle:@"提醒" message:@"你还未设置资金密码,请先设置资金密码" preferredStyle:UIAlertControllerStyleAlert];
            [alterVC addAction:[UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                // 去设置资金密码
                SafePwdSetViewController *safePwdVC = [[SafePwdSetViewController alloc] init];
                [self bh_PushViewController:safePwdVC hiddenTabbar:YES];
            }]];
            [alterVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
            [self presentViewController:alterVC animated:YES completion:nil];
        }else{
            PullCoinViewController *pullVC = [PullCoinViewController new];
            pullVC.coinModels = self.coinModels;
            [self bh_PushViewController:pullVC hiddenTabbar:YES];
        }
    }];
    
    [self.viewModel.pushClickSubject subscribeNext:^(id  _Nullable x) {
        // 冲币
        PushCoinViewController *pushVC = [PushCoinViewController new];
        pushVC.coinModels = self.coinModels;
        [self bh_PushViewController:pushVC hiddenTabbar:YES];
    }];
    
    [self.viewModel.walletClickSubject subscribeNext:^(id  _Nullable x) {
        // 钱包地址
        CoinListViewController *listVC = [[CoinListViewController alloc] init];
        listVC.coinModels = self.coinModels;
        listVC.nextViewController = [WalletViewController class];
        [self.navigationController pushViewController:listVC animated:YES];
    }];
    
    [self.viewModel.recordClickSubject subscribeNext:^(id  _Nullable x) {
        // 交易记录
        CoinRecordViewController *recordVC = [CoinRecordViewController new];
        recordVC.coinModels = self.coinModels;
        [self bh_PushViewController:recordVC hiddenTabbar:YES];
    }];
}

- (AssetDetailMainView *)mainView
{
    if(!_mainView){
        _mainView = [[AssetDetailMainView alloc] initWithFrame:self.view.bounds viewModel:self.viewModel];
    }
    return _mainView;
}

- (AssetDetailViewModel *)viewModel
{
    if(!_viewModel){
        _viewModel = [[AssetDetailViewModel alloc] init];
        _viewModel.coinModels = self.coinModels;
    }
    return _viewModel;
}

@end
